package middleware

import (
	"time"

	"github.com/gin-gonic/gin"
	"github.com/ulule/limiter/v3"
	mgin "github.com/ulule/limiter/v3/drivers/middleware/gin"
	"github.com/ulule/limiter/v3/drivers/store/memory"
)

func Limit(times int64, inDuration time.Duration, options ...mgin.Option) gin.HandlerFunc {
	rate := limiter.Rate{Limit: times, Period: inDuration}
	store := memory.NewStore()
	limit := limiter.New(store, rate)
	midware := mgin.NewMiddleware(limit, options...)
	return midware
}
